package com.xiaozhou.leetCode.LeetCode200;

public class LeetCode209 {

    public static int minSubArrayLen(int target, int[] nums) {
        int left=0,right=0,sum=0;
        int min = Integer.MAX_VALUE;
        while (right < nums.length){
            if (nums[right] == target){
                return 1;
            }
            sum += nums[right];
            if (sum >= target){
                min = Math.min(min, right - left + 1);
                while (sum >= target){
                    min = Math.min(min, right - left + 1);
                    sum -= nums[left];
                    left += 1;
                }
            }
            right++;
        }
        return min == Integer.MAX_VALUE ? 0 : min;
    }

    public static void main(String[] args) {
        int[] nums = {2,3,1,2,4,3};
        int i = minSubArrayLen(7, nums);
        System.out.println(i);
    }
}
